//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Settings.h"
#include "Unit1.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormSettings *FormSettings;
//---------------------------------------------------------------------------
__fastcall TFormSettings::TFormSettings(TComponent* Owner)
        : TForm(Owner)
{
   TIniFile *ini;
   ini = new TIniFile( ChangeFileExt( Forms::Application->ExeName, ".INI" ) );

 TWAIN_OrganizationLicense("zzz",520069446);
 int c_scan = TWAIN_GetSourceList();

 AnsiString t_name_scan="!";
 while(t_name_scan!="")
 {
 t_name_scan=TWAIN_NextSourceName();
 ComboBoxScan->Items->Add(t_name_scan);
 }
   t_name_scan=  ini->ReadString( "LocalScanner", "NameScanner","" );
   ComboBoxScan->ItemIndex=ComboBoxScan->Items->IndexOf(t_name_scan);
   Form1->NameScan = t_name_scan;

   t_name_scan=  ini->ReadString( "LocalScanner", "KeyLocal","" );
   ComboBoxL->ItemIndex=ComboBoxL->Items->IndexOf(t_name_scan);
   if(ComboBoxL->ItemIndex>=0)
   {
   Form1->KeyLocal = (unsigned short)t_name_scan[1];
   Form1->BitBtnLocal->Caption="Ctrl+"+ComboBoxL->Text;
   }
   t_name_scan=  ini->ReadString( "LocalScanner", "KeyServer","" );
   ComboBoxS->ItemIndex=ComboBoxS->Items->IndexOf(t_name_scan);
   if(ComboBoxS->ItemIndex>=0)
   {
   Form1->KeyServer = (unsigned short)t_name_scan[1];
   Form1->BitBtnServer->Caption="Ctrl+"+ComboBoxS->Text;
   }

   EditServer->Text = ini->ReadString( "ServerScanner", "Host","");
   Form1->ClientSocket1->Host = EditServer->Text;
   EditPort->Text = ini->ReadString( "ServerScanner", "Port","7777");
   Form1->ClientSocket1->Port =StrToInt(EditPort->Text);
   delete ini;
}
//---------------------------------------------------------------------------
void __fastcall TFormSettings::Button1Click(TObject *Sender)
{
   TIniFile *ini;
   ini = new TIniFile( ChangeFileExt( Forms::Application->ExeName, ".INI" ) );

   ini->WriteString( "LocalScanner", "NameScanner",ComboBoxScan->Text);
   ini->WriteString( "LocalScanner", "KeyLocal",ComboBoxL->Text);
   ini->WriteString( "LocalScanner", "KeyServer",ComboBoxS->Text);
   ini->WriteString( "ServerScanner", "Host",EditServer->Text);
   ini->WriteString( "ServerScanner", "Port",EditPort->Text);
   delete ini;
   this->Close();
}
//---------------------------------------------------------------------------



